Skip to main content

Events

Subscribe functions to lifecycle events to execute code when specific actions occur.

Overview

Events allow you to trigger functions automatically when certain actions happen in your application. Subscribe functions to events like user creation, data updates, or custom triggers to build reactive workflows.


Concepts

Event

A notification that something has occurred in your application. Events have a type (e.g., POST_USER_CREATE) and carry data about what happened.

Event Subscription

A connection between an event and a function. When the event fires, all subscribed functions are executed.

Pre/Post Events

  • Pre Events: Fire before an action completes (can block or modify)
  • Post Events: Fire after an action completes (for side effects)

View Events

  1. Navigate to your App in the Dashboard.
  2. Click Events in the sidebar.
  3. View all available event types with:
    • Event Name: The event type
    • Subscribers: Number of subscribed functions
    • Description: What triggers this event

Available Event Types

User Events

EventDescription
PRE_USER_CREATEBefore a new user is created
POST_USER_CREATEAfter a new user is created
PRE_USER_UPDATEBefore a user is updated
POST_USER_UPDATEAfter a user is updated
PRE_USER_DELETEBefore a user is deleted
POST_USER_DELETEAfter a user is deleted

Authentication Events

EventDescription
POST_LOGINAfter successful login
POST_LOGOUTAfter user logout
POST_PASSWORD_RESETAfter password reset

Data Events

EventDescription
PRE_RECORD_CREATEBefore a record is created
POST_RECORD_CREATEAfter a record is created
PRE_RECORD_UPDATEBefore a record is updated
POST_RECORD_UPDATEAfter a record is updated
PRE_RECORD_DELETEBefore a record is deleted
POST_RECORD_DELETEAfter a record is deleted

Subscribe a Function

  1. Navigate to Events in your app.
  2. Find the event you want to subscribe to.
  3. Click the event card to expand it.
  4. Click Subscribe Function.
  5. Select the function to subscribe.
  6. Click Subscribe.
tip

Subscribe to PRE_* events when you need to validate or modify data before an action. Subscribe to POST_* events for notifications, logging, or side effects.


View Event Subscribers

  1. Navigate to Events in your app.
  2. Click on an event card.
  3. View the list of subscribed functions:
    • Function Name: The subscribed function
    • Status: Active or Inactive
    • Subscribed Date: When it was subscribed

Unsubscribe a Function

  1. Navigate to Events in your app.
  2. Click on the event.
  3. Find the function in the subscribers list.
  4. Click Unsubscribe.
  5. Confirm the action.

Event Handler Structure

When a function is triggered by an event, it receives event data:

def handler(request, context):
# Get event data
event_type = context.event_type
event_data = context.event_data

# Event data contains details about what happened
user_id = event_data.get("user_id")
changes = event_data.get("changes")

# Perform your logic
if event_type == "POST_USER_CREATE":
send_welcome_email(event_data["email"])

return {"status": "ok"}

Pre-Event Handlers

Pre-event handlers can modify or block actions:

def handler(request, context):
event_data = context.event_data

# Validate user data before creation
if not is_valid_email(event_data["email"]):
return {
"allow": False,
"message": "Invalid email address"
}

# Allow the action to proceed
return {"allow": True}

Configuration

Subscription Settings

SettingDescription
FunctionThe function to execute
PriorityExecution order (lower = first)
ActiveEnable/disable the subscription

Best Practices

  1. Use POST events for side effects: Logging, notifications, analytics
  2. Use PRE events for validation: Input validation, authorization checks
  3. Keep handlers fast: Event handlers should complete quickly
  4. Handle errors gracefully: Don't let handler errors break the main flow
  5. Avoid infinite loops: Don't trigger events that call the same handler

Limits

ResourceLimit
Subscriptions per event10
Handler timeout10 seconds
Event payload size1 MB
info

Need higher limits? Contact support to discuss your requirements.


Troubleshooting

Event handler not triggering

Problem: A subscribed function isn't being called when the event fires.

Solution:

  1. Verify the function is Active.
  2. Check the subscription is Active.
  3. Confirm the event type matches what you're triggering.
  4. Check function execution history for errors.

Pre-event blocking unexpectedly

Problem: Actions are being blocked when they shouldn't be.

Solution:

  1. Review the pre-event handler code.
  2. Check the handler is returning {"allow": True} for valid cases.
  3. Add logging to identify the blocking condition.

Handler receiving wrong data

Problem: Event data doesn't contain expected fields.

Solution:

  1. Log the full event_data to see what's available.
  2. Check the event type documentation for expected fields.
  3. Verify you're subscribing to the correct event type.

Last Updated: January 2025